package ext.acae2.utilities.container;

import wt.fc.PersistenceHelper;
import wt.fc.QueryResult;
import wt.pdmlink.PDMLinkProduct;
import wt.query.ClassAttribute;
import wt.query.OrderBy;
import wt.query.OrderByExpression;
import wt.query.QuerySpec;
import wt.query.SearchCondition;

public class CSCProduct {
	/*
	 * Answer a PDMLinkProduct by Searching Product Name
	 * @param prdName - the String object used as search criteria in the retrieval of PDMLinkProduct  
	 * @return PDMLink Product
	 * @excption 
	 */
	public static PDMLinkProduct getPDMLinkProduct(String prdName){
		//Vector vProduct = new Vector();
		try{
			PDMLinkProduct product = null;
			QuerySpec qs = new QuerySpec(PDMLinkProduct.class);
			SearchCondition sc = new
					SearchCondition(PDMLinkProduct.class, PDMLinkProduct.NAME, SearchCondition.EQUAL,prdName,false);
			qs.appendSearchCondition(sc);
			
	        ClassAttribute clsAttr = new ClassAttribute(PDMLinkProduct.class,PDMLinkProduct.MODIFY_TIMESTAMP);
	        OrderBy order = new OrderBy((OrderByExpression)clsAttr,true);
	        qs.appendOrderBy(order);
			
			QueryResult qr = PersistenceHelper.manager.find(qs);

			if (qr.hasMoreElements()){
				product = (PDMLinkProduct)qr.nextElement();				
				return product;
			}
		}catch(Exception ex){
			//vProduct = null;
//			System.out.println("Exception Message = " + ex.getMessage()); //Debug
		}
		return null;
	}
}
